<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

	<title>Class: CurrencySpy::Nbp</title>

	<link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />

	<script src="../js/jquery.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/thickbox-compressed.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/quicksearch.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/darkfish.js" type="text/javascript"
		charset="utf-8"></script>

</head>
<body class="class">

	<div id="metadata">
		<div id="home-metadata">
			<div id="home-section" class="section">
        <h3 class="section-header">
          <a href="../index.html">Home</a>
          <a href="../index.html#classes">Classes</a>
          <a href="../index.html#methods">Methods</a>
        </h3>
			</div>
		</div>

		<div id="file-metadata">
			<div id="file-list-section" class="section">
				<h3 class="section-header">In Files</h3>
				<div class="section-body">
					<ul>
					
						<li><a href="../lib/currency_spy/nbp_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
							class="thickbox" title="lib/currency_spy/nbp.rb">lib/currency_spy/nbp.rb</a></li>
					
					</ul>
				</div>
			</div>

			
		</div>

		<div id="class-metadata">

			<!-- Parent Class -->
			
			<div id="parent-class-section" class="section">
				<h3 class="section-header">Parent</h3>
				
				<p class="link"><a href="Scraper.html">CurrencySpy::Scraper</a></p>
				
			</div>
			

			<!-- Namespace Contents -->
			

			<!-- Method Quickref -->
			
			<div id="method-list-section" class="section">
				<h3 class="section-header">Methods</h3>
				<ul class="link-list">
					
					<li><a href="#method-c-new">::new</a></li>
					
					<li><a href="#method-i-buy_rate">#buy_rate</a></li>
					
					<li><a href="#method-i-rate_time">#rate_time</a></li>
					
					<li><a href="#method-i-sell_rate">#sell_rate</a></li>
					
				</ul>
			</div>
			

			<!-- Included Modules -->
			
		</div>

		<div id="project-metadata">
			
			
			<div id="fileindex-section" class="section project-section">
				<h3 class="section-header">Files</h3>
				<ul>
				
					<li class="file"><a href="../Gemfile.html">Gemfile</a></li>
				
					<li class="file"><a href="../LICENSE.html">LICENSE</a></li>
				
					<li class="file"><a href="../README_rdoc.html">README.rdoc</a></li>
				
					<li class="file"><a href="../Rakefile.html">Rakefile</a></li>
				
					<li class="file"><a href="../nbproject/private/rake-d_txt.html">rake-d.txt</a></li>
				
				</ul>
			</div>
			

			<div id="classindex-section" class="section project-section">
				<h3 class="section-header">Class Index
					<span class="search-toggle"><img src="../images/find.png"
						height="16" width="16" alt="[+]"
						title="show/hide quicksearch" /></span></h3>
				<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
				<fieldset>
					<legend>Quicksearch</legend>
					<input type="text" name="quicksearch" value=""
						class="quicksearch-field" />
				</fieldset>
				</form>

				<ul class="link-list">
				
					<li><a href="../CurrencySpy.html">CurrencySpy</a></li>
				
					<li><a href="../CurrencySpy/DnbNord.html">CurrencySpy::DnbNord</a></li>
				
					<li><a href="../CurrencySpy/Nbp.html">CurrencySpy::Nbp</a></li>
				
					<li><a href="../CurrencySpy/Scraper.html">CurrencySpy::Scraper</a></li>
				
					<li><a href="../CurrencySpy/Walutomat.html">CurrencySpy::Walutomat</a></li>
				
				</ul>
				<div id="no-class-search-results" style="display: none;">No matching classes.</div>
			</div>

			
		</div>
	</div>

	<div id="documentation">
		<h1 class="class">CurrencySpy::Nbp</h1>

		<div id="description">
			<p>
A class designed to fetch currency information from the website of The
Polish National Bank (Narodowy Bank Polski).
</p>

		</div>

		<!-- Constants -->
		

		<!-- Attributes -->
		

		<!-- Methods -->
		
		<div id="public-class-method-details" class="method-section section">
			<h3 class="section-header">Public Class Methods</h3>

		
			<div id="new-method" class="method-detail ">
				<a name="method-c-new"></a>

				<div class="method-heading">
				
					<span class="method-name">new</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Constructor method. Initializes the following:
</p>
<ul>
<li><p>
a url of the source
</p>
</li>
<li><p>
and the name of the source
</p>
</li>
<li><p>
a list of currency codes available
</p>
</li>
</ul>
					

					
					<div class="method-source-code"
						id="new-source">
<pre>
    <span class="ruby-comment cmt"># File lib/currency_spy/nbp.rb, line 10</span>
10:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>
11:       <span class="ruby-keyword kw">super</span>
12:       <span class="ruby-ivar">@url</span> = <span class="ruby-value str">'http://www.nbp.pl/home.aspx?f=/kursy/kursyc.html'</span>
13:       <span class="ruby-ivar">@institution</span> = <span class="ruby-value str">&quot;Narodowy Bank Polski&quot;</span>
14:       <span class="ruby-ivar">@available_codes</span> = <span class="ruby-node">%(EUR USD GBP CHF AUS AUD CAD CZK DKK NOK SEK)</span>
15:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	
		<div id="public-instance-method-details" class="method-section section">
			<h3 class="section-header">Public Instance Methods</h3>

		
			<div id="buy-rate-method" class="method-detail ">
				<a name="method-i-buy_rate"></a>

				<div class="method-heading">
				
					<span class="method-name">buy_rate</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Get the buying rate from the parsed website
</p>
					

					
					<div class="method-source-code"
						id="buy-rate-source">
<pre>
    <span class="ruby-comment cmt"># File lib/currency_spy/nbp.rb, line 18</span>
18:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">buy_rate</span>
19:       <span class="ruby-identifier">regexp</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">currency_code</span>)
20:       <span class="ruby-identifier">page</span>.<span class="ruby-identifier">search</span>(<span class="ruby-value str">'//tr[@valign=&quot;middle&quot;]'</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">tr</span><span class="ruby-operator">|</span>
21:         <span class="ruby-identifier">tr</span>.<span class="ruby-identifier">search</span>(<span class="ruby-value str">'td'</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">td</span><span class="ruby-operator">|</span>
22:           <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">regexp</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">td</span>.<span class="ruby-identifier">content</span>))
23:             <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">td</span>.<span class="ruby-identifier">next_element</span>.<span class="ruby-identifier">content</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-value str">','</span>,<span class="ruby-value str">'.'</span>).<span class="ruby-identifier">to_f</span>
24:           <span class="ruby-keyword kw">end</span>
25:         <span class="ruby-keyword kw">end</span>
26:       <span class="ruby-keyword kw">end</span>
27:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
28:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="rate-time-method" class="method-detail ">
				<a name="method-i-rate_time"></a>

				<div class="method-heading">
				
					<span class="method-name">rate_time</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Get the time for this rate (based on the information on the website)
</p>
					

					
					<div class="method-source-code"
						id="rate-time-source">
<pre>
    <span class="ruby-comment cmt"># File lib/currency_spy/nbp.rb, line 44</span>
44:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rate_time</span>
45:       <span class="ruby-identifier">regexp</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-regexp re">/\d\d\d\d-\d\d-\d\d/</span>)
46:       <span class="ruby-identifier">res</span> = <span class="ruby-keyword kw">nil</span>
47:       <span class="ruby-identifier">page</span>.<span class="ruby-identifier">search</span>(<span class="ruby-value str">'//p[@class=&quot;nag&quot;]'</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span>
48:         <span class="ruby-identifier">p</span>.<span class="ruby-identifier">search</span>(<span class="ruby-value str">'b'</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">b</span><span class="ruby-operator">|</span>
49:           <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">regexp</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">b</span>.<span class="ruby-identifier">content</span>))
50:             <span class="ruby-identifier">res</span> = <span class="ruby-identifier">b</span>.<span class="ruby-identifier">content</span>
51:           <span class="ruby-keyword kw">end</span>
52:         <span class="ruby-keyword kw">end</span>
53:       <span class="ruby-keyword kw">end</span>
54:       <span class="ruby-keyword kw">return</span> <span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">strptime</span>(<span class="ruby-identifier">res</span>, <span class="ruby-value str">&quot;%Y-%m-%d&quot;</span>)
55:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="sell-rate-method" class="method-detail ">
				<a name="method-i-sell_rate"></a>

				<div class="method-heading">
				
					<span class="method-name">sell_rate</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Get the selling rate from the parsed website
</p>
					

					
					<div class="method-source-code"
						id="sell-rate-source">
<pre>
    <span class="ruby-comment cmt"># File lib/currency_spy/nbp.rb, line 31</span>
31:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sell_rate</span>
32:       <span class="ruby-identifier">regexp</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">currency_code</span>)
33:       <span class="ruby-identifier">page</span>.<span class="ruby-identifier">search</span>(<span class="ruby-value str">'//tr[@valign=&quot;middle&quot;]'</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">tr</span><span class="ruby-operator">|</span>
34:         <span class="ruby-identifier">tr</span>.<span class="ruby-identifier">search</span>(<span class="ruby-value str">'td'</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">td</span><span class="ruby-operator">|</span>
35:           <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">regexp</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">td</span>.<span class="ruby-identifier">content</span>))
36:             <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">td</span>.<span class="ruby-identifier">next_element</span>.<span class="ruby-identifier">next_element</span>.<span class="ruby-identifier">content</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-value str">','</span>,<span class="ruby-value str">'.'</span>).<span class="ruby-identifier">to_f</span>
37:           <span class="ruby-keyword kw">end</span>
38:         <span class="ruby-keyword kw">end</span>
39:       <span class="ruby-keyword kw">end</span>
40:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
41:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	

	</div>


	<div id="rdoc-debugging-section-dump" class="debugging-section">
	
		<p>Disabled; run with --debug to generate this.</p>
	
	</div>

	<div id="validator-badges">
		<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
		<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
			Rdoc Generator</a> 1.1.6</small>.</p>
	</div>

</body>
</html>

